Ext.require(['*']);
Ext.tip.QuickTipManager.init();
	var strTreeGc = Ext.create('Ext.data.TreeStore', {  
		root: {  
			expanded: true,  
			children: [  
				{  
					text: 'Non Tournament',  
					leaf: false,  
					expanded: true,  
					children: [    
						{  
							text: 'Tee Time',  
							leaf: true,
							url: base_url+'/NtTeeTime'
						},
						{  
							text: 'Live Scoring',  
							leaf: true,
							url: base_url+'/NtLiveScore'  
						},
						{  
							text: 'Leader board',  
							leaf: true  
						}     
					]  
				},{  
					text: 'Tournament',  
					leaf: false,  
					expanded: true,  
					children: [  
						{  
							text: 'Tournament',  
							leaf: true  
						},  
						{  
							text: 'Schedule',  
							leaf: true  
						},  
						{  
							text: 'Scores',  
							leaf: true  
						},
						{  
							text: 'Grup Leader board',  
							leaf: true  
						},
						{  
							text: 'Score Leader board',  
							leaf: true  
						},
						{  
							text: 'Champion Leader board',  
							leaf: true  
						}
					]  
				}      
			]  
		}  
	});  
	
	var strTreeSetting = Ext.create('Ext.data.TreeStore', {  
		root: {  
			expanded: true,  
			children: [  
				{  
					text: 'Player Content',  
					leaf: false,  
					expanded: true,  
					children: [  
						{  
							text: 'Players',  
							leaf: true ,
							url: base_url+'/Player'
						},  
						{  
							text: 'Company',  
							leaf: true,
							url: base_url+'/Company'							
						},  
						{  
							text: 'Member',  
							leaf: true,
							url: base_url+'/Member'
						}    
					]  
				},{  
					text: 'Golf Course',  
					leaf: false,  
					expanded: true,  
					children: [  
						{  
							text: 'Flag',  
							leaf: true,
							url: base_url+'/Flag'  
						},  
						{  
							text: 'Flag Field',  
							leaf: true,
							url: base_url+'/FlagField'  
						},  
						{  
							text: 'Tee Box',  
							leaf: true,
							url: base_url+'/TeeBox'  
						},   
						{  
							text: 'Golf Course',  
							leaf: true,
							url: base_url+'/GolfCourse'  
						},  
						{  
							text: 'Hole Golf Course',  
							leaf: true,
							url: base_url+'/HoleGolfCourse'  
						}   
					]  
				}
			]  
		}  
	});  
	
	var treeGc = Ext.create('Ext.tree.Panel', {
		region: 'center',
		layout: 'fit',
		rootVisible: false,
		autoScroll: true,
		store: strTreeGc,
		listeners: {
			select: function(selModel, record) {
				var selectedNode = treeGc.getSelectionModel().getSelection();
				if (record.get('leaf')) {
					url 	= selectedNode[0].raw.url;
					text 	= selectedNode[0].raw.text;
					Ext.getBody().mask('Loading Setting '+text+'....','x-mask-loading');
					Ext.get("content").load({ 
						url: url,
						scripts:true,
						callback: function() {Ext.getBody().unmask();  } 						
					});
				}
			}
		}
	});
	
	var treeSett = Ext.create('Ext.tree.Panel', {
		region: 'center',
		layout: 'fit',
		rootVisible: false,
		autoScroll: true,
		store: strTreeSetting,
		listeners: {
			select: function(selModel, record) {
				var selectedNode = treeSett.getSelectionModel().getSelection();
				if (record.get('leaf')) {
					url 	= selectedNode[0].raw.url;
					text 	= selectedNode[0].raw.text;
					Ext.getBody().mask('Loading Setting '+text+'....','x-mask-loading');
					Ext.get("content").load({ 
						url: url,
						scripts:true,
						callback: function() {Ext.getBody().unmask();  } 						
					});
				}
			}
		}
	});
	
	var contentPanel = {
		 // title: 'Main',
		 id: 'content-panel',
		 region: 'center', 
		 border: false, 
		 layout: 'fit',
		 contentEl: 'cont',
		 items: []
	};
	
	var accordionPanel = {
		layout: 'accordion',
		id: 'accordion-panel',
		height: '100%',
		items:[{
			title: 'Golf Content',
			height: '100%',
			items: [treeGc]
		},{
			title: 'Setting',
			height: '100%',
			items: [treeSett]
		}]
	}
	
	Ext.onReady(function() {
		
		
	var viewport = Ext.create('Ext.Viewport', {
		layout: {
			type: 'border',
			padding: 5
		},
		defaults: {
			split: true
		},
		items: [
				// {
					// xtype: 'box',
					// id: 'header',
					// region: 'north',
					// height: 70
				// },
				{
					 region: 'west', 
					 layout: 'fit',
					 split: true,
					 title: 'Menu',
					 border:'false',
					 width:250,
					 maxWidth: 250,
					 minWidth: 250,
					 height: '100%',
					 collapsible:true,
					 items: [accordionPanel]
				},contentPanel]
	});
	
});